//
//  SelectDistrictCell.m
//  YunGui
//
//  Created by wmm on 16/5/17.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "SelectDistrictCell.h"
#import "MIneDistrictModel.h"

@interface SelectDistrictCell ()
{
    UIView   *_backView;
    CGFloat   space;
    
    UILabel  *_subdistrictNameLabel;//小区
    UILabel  *_propertyLabel;//物业
    UILabel  *_areaLabel;//地区
    UILabel  *_addressLabel;//地址
    UILabel  *_responsePersonLabel;//负责人
    UILabel  *_creatpersonLabel;//创建人
}
@end

@implementation SelectDistrictCell

+ (instancetype)cellWithTabelView:(UITableView *)tableView
{
    static NSString *SelectDistrictCellid = @"SelectDistrictCellID";
    
    SelectDistrictCell *cell = [tableView dequeueReusableCellWithIdentifier:SelectDistrictCellid];
    if (!cell) {
        cell = [[SelectDistrictCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SelectDistrictCellid];
        [cell addSubviews];
    }
    return cell;
}

- (void)addSubviews
{
    space = [UIView getWidth:10.0f];
    CGFloat cellH = [SelectDistrictCell cellHeight];
    _backView =[[UIView alloc] initWithFrame:CGRectMake(1.5 * space, space, kScreenWidth - 3 * space, cellH - space)];
    _backView.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:_backView];
    
    //小区名图片
    UIImageView  *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(1.5 * space, 1.5 * space, 20.0f, 20.0f)];
    imageView1.image = [UIImage imageNamed:@"Btn_Normal_Xiaoquming"];
    //    imageView1.backgroundColor = BlueColor;
    [_backView addSubview:imageView1];
    
    UILabel   *nameLabel = [ViewTool getLabelWith:CGRectMake(imageView1.maxX + 5, imageView1.y, 60.0f, 20.0f) WithTitle:@"小区名:" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel];
    
    _subdistrictNameLabel = [ViewTool getLabelWith:CGRectMake(nameLabel.maxX, nameLabel.y, _backView.width - nameLabel.maxX, 20.0f) WithTitle:@"郎诗保利簏院. 大别墅" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_subdistrictNameLabel];
    
    //-----------------------------------
    UIImageView  *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(imageView1.x, imageView1.maxY + space, 20.0f, 20.0f)];
    imageView2.image = [UIImage imageNamed:@"Btn_Nor_Wuye"];
    //    imageView2.backgroundColor = BlueColor;
    [_backView addSubview:imageView2];
    
    UILabel   *nameLabel1 = [ViewTool getLabelWith:CGRectMake(imageView1.maxX + 5, imageView2.y, 60.0f, 20.0f) WithTitle:@"物业名:" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel1];
    
    _propertyLabel = [ViewTool getLabelWith:CGRectMake(nameLabel1.maxX, imageView2.y, _subdistrictNameLabel.width, 20.0f) WithTitle:@"张全蛋" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_propertyLabel];
    
    //*-*-*-*-*-------------------------
    UIImageView  *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(imageView1.x, imageView2.maxY + space, 20.0f, 20.0f)];
    imageView3.image = [UIImage imageNamed:@"Btn_Nor_Lianxiren"];
    //    imageView2.backgroundColor = BlueColor;
    [_backView addSubview:imageView3];
    
    UILabel   *nameLabel2 = [ViewTool getLabelWith:CGRectMake(imageView1.maxX + 5, imageView3.y, 60.0f, 20.0f) WithTitle:@"负责人:" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel2];
    
    _responsePersonLabel = [ViewTool getLabelWith:CGRectMake(nameLabel2.maxX, imageView3.y, _subdistrictNameLabel.width, 20.0f) WithTitle:@"张全蛋" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_responsePersonLabel];
    //*-------------------------------
    
    
    UIImageView *addressImage = [[UIImageView alloc] initWithFrame:CGRectMake(imageView1.x, imageView3.maxY +  space, 20.0f, 20.0f)];
    addressImage.image = [UIImage imageNamed:@"Btn_Normal_Diqu"];
    [_backView addSubview:addressImage];
    
    UILabel   *nameLabel3 = [ViewTool getLabelWith:CGRectMake(addressImage.maxX + 5, addressImage.y+3, 40.0f, 15.0f) WithTitle:@"地区:" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel3];
    
    _areaLabel = [ViewTool getLabelWith:CGRectMake(nameLabel3.maxX, addressImage.y+3, 120.0f, 15.0f) WithTitle:@"江苏 南京 玄武区" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_areaLabel];
    
    
    UIImageView *creatImage = [[UIImageView alloc] initWithFrame:CGRectMake(_backView.width - 135.0f,addressImage.y, 20.0f, 20.0f)];
    creatImage.image = [UIImage imageNamed:@"Btn_Normal_Jingzhengduishou"];
    [_backView addSubview:creatImage];
    
    // 后面的宽度110
    UILabel   *nameLabel4 = [ViewTool getLabelWith:CGRectMake(creatImage.maxX + 5, addressImage.y+3 , 50.0f, 15.0f) WithTitle:@"创建人:" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel4];
    
    _creatpersonLabel = [ViewTool getLabelWith:CGRectMake(nameLabel4.maxX, addressImage.y+3, 60.0f, 15.0f) WithTitle:@"赵铁牛" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_creatpersonLabel];
    
    
    UIImageView  *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(imageView1.x, creatImage.maxY + space, 20.0f, 20.0f)];
    imageView4.image = [UIImage imageNamed:@"Btn_Normal_Didian"];
    //    imageView2.backgroundColor = BlueColor;
    [_backView addSubview:imageView4];
    
    UILabel   *nameLabel5 = [ViewTool getLabelWith:CGRectMake(imageView1.maxX + 5, imageView4.y+3, 40.0f, 15.0f) WithTitle:@"地址:" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel5];
    
    _addressLabel = [ViewTool getLabelWith:CGRectMake(nameLabel5.maxX, imageView4.y+3, _subdistrictNameLabel.width, 15.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_addressLabel];
}
- (void)setModel:(MIneDistrictModel *)model
{
    _model = model;
    _subdistrictNameLabel.text = model.title;
    _propertyLabel.text = model.property;
    _responsePersonLabel.text = model.m_user_name;
    _creatpersonLabel.text = model.user_name;
    
    NSString *placeStr;
    if ([model.province isEqualToString:model.city]) {
        placeStr = [NSString stringWithFormat:@"%@ %@",model.province,model.district];
    }else{
        placeStr = [NSString stringWithFormat:@"%@ %@ %@",model.province,model.city,model.district];
    }
    //    NSString *placeStr = [NSString stringWithFormat:@"%@ %@",model.province,model.city];
    _areaLabel.text = placeStr;
    _addressLabel.text = model.address;
    
    if(model.is_visit == 1){
        NSLog(@"model.is_visit:%d",model.is_visit);
        _backView.backgroundColor = UIColorFromRGB(0xf4f4f4);
        self.userInteractionEnabled = NO;
    }else{
        _backView.backgroundColor = [UIColor whiteColor];
        self.userInteractionEnabled = YES;
    }
}
+ (CGFloat)cellHeight
{
    return [UIView getHeight:170];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    
    // Configure the view for the selected state
}

@end
